<!-- Following is the code for cb ultimate invideo ads settings  -->
{$tcomments_params = ['function'=>'get_ultimate_ads']}
{$current_ad = get_my_function($tcomments_params)}
{if !empty($current_ad)}
	{$play_ad = true}
{/if}
<!-- End  -->

<!-- This code is added for timecomments plugin-->
{$tcomments_params = ['function'=>'get_timeCommnets','videoid'=>$vdata.videoid]}
{$Comments_allowed =  $myquery->is_commentable($vdata,'v') }
{$timecomments = get_my_function($tcomments_params)}
<!-- End -->

<!-- This code is added for instance manager Interactive ads plugin-->
{$v_editor_params = ['function'=>'get_video_editor']}
{$video_editor_enabled = get_my_function($v_editor_params)}
<!-- End -->

{$svg_manager_params = ['function'=>'get_svg_manager']}
{$svg_manager = get_my_function($svg_manager_params)}
{if $svg_manager}
{$svg_manager}	
{/if}


<!-- This code is added for instance manager Interactive ads plugin intances-->
{if !$video_editor_enabled }
	{$intance_params = ['function'=>'get_slot','videoid'=>$vdata.videoid]}
	{$active_instances = get_my_function($intance_params)}
	{if is_array($active_instances)}
		{$active_instances = json_encode($active_instances)}
	{/if}
{/if}
<!-- End -->


<link rel="stylesheet" href="{$cb_vjs_player_url}/css/video-js.min.css">
<link href="{$cb_vjs_player_url}/css/cb_vjs_plugin.css" rel="stylesheet">
<link href="{$cb_vjs_player_url}/css/videojs.ads.css" rel="stylesheet">
<link href="{$cb_vjs_player_url}/css/videojs.ima.css" rel="stylesheet">
<link href="{$cb_vjs_player_url}/css/cb_vjs_resolution.css" rel="stylesheet">
<link href="{$cb_vjs_player_url}/css/videojs-chromecast.css" rel="stylesheet">
<link href="{$cb_vjs_player_url}/css/videojs.thumbnails.css" rel="stylesheet">

{if $development_mode}
<script src="{$cb_vjs_player_url}/js/video-js.js"></script>
{else}
<script src="{$cb_vjs_player_url}/js/video-js.min.js"></script>
{/if}
<script src="{$cb_vjs_player_url}/js/cb_vjs_custom.js"></script>
<script src="{$cb_vjs_player_url}/js/cb_vjs_plugin.js"></script>
<script src="{$cb_vjs_player_url}/js/cb_vjs_resolution.js"></script>
{if $cb_timecomments_plugin == 'installed'}
<script src="{$cb_vjs_player_url}/js/timecomments.js"></script>
{/if}
{if $play_ad == true}
<script src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
{/if}
{if $video_editor_enabled}
<script type="text/javascript" src="{$cb_ia_ads_url}/assets/js/instance_manager.js"></script>
{/if}
{if $active_instances && !$video_editor_enabled}
<script type="text/javascript" src="{$cb_ia_ads_url}/assets/js/interactive.js"></script>
{/if}
<script src="{$cb_vjs_player_url}/js/videojs.ads.js"></script>
<script src="{$cb_vjs_player_url}/js/videojs.ima.js"></script>
<script src="{$cb_vjs_player_url}/js/cb_ultimate_ads.js"></script>
<script src="{$cb_vjs_player_url}/js/iphone-inline-video.browser.js"></script>

<script src="{$cb_vjs_player_url}/js/videojs.thumbnails.js"></script>


{$default_quality = get_cbvjs_quality_type($video_files)}
<video playsinline id="cb_video_js_{$vdata.videoid}" class="video-js vjs-default-skin" height="{$height}" width="{$width}" poster="{getThumb vdetails=$vdata size=768x432}" >

    {foreach $video_files as $file}
    {$quality = get_cbvjs_quality($file)}

    {if $flv_vid == true}
    	<source src='{$file}' type="video/x-flv" />
    {else}
    	<source src='{$file}' type="video/mp4" label="{strtoupper($quality)}" res="{$quality}"  />
    {/if}
    {/foreach}
    {ANCHOR place="play_def_sub" data=$vdata.videoid }
    <p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>
</video>


<script type="text/javascript">
	var vid_id = "{$vdata.videoid}";
	var videotitle = "{$vdata.title|escape_quotes}";
	var uploader = "{$vdata.username}";
	var branding_logo  = "{$cb_logo}";
	var product_link = "{$player_config.player_logo_url}";
	var show_logo = true;
	var default_res = "{$default_quality}";
	var autoplay = "{$player_config.autoplay}";


	if (autoplay == 'no' || navigator.userAgent.match(/Android/i) ){
		autoplay = false;
	}else{
		autoplay = true;
	}

	//this condition is added for video head control advanced plugin
	var video_head = "{$vdata.video_head}";
	var controls = true;
	var loop = false;
	var muted = false;
	if (video_head == true){
		controls = false;
		muted = true; 
		autoplay = true;
		loop = true;
	}

	//player settings
	var cb_player_setup = {
		plugins : { }, 
		"techOrder" : ['html5', 'flash'],
		"controls": controls,
		"autoplay": autoplay,
		"preload": "auto",
		"muted": muted,
		"loop" : loop
	};

	var cb_timecomments_plugin = "{$cb_timecomments_plugin}"; // timecomments settings
	if (cb_timecomments_plugin){
		var user_id = "{userid()}";
		var username = "{username()}";
		var user_profile  = "{$userquery->avatar('','m',userid())}";
		var allow_comments = "{$Comments_allowed}";
	}

	var play_ad = "{$play_ad}"; //  Ad settings starts to pass on to player
	if (play_ad){
		var ad_code = "{$current_ad.ad_tag}";
		var ad_id = "{$current_ad.ad_id}";
	}



	var video_editor_enabled = "{$video_editor_enabled}"; // Interactive Ads plugin settings
	var i_instances = '{$active_instances}';

	//Setting CallBack
	var cb_vjs_callback = function(){
		var cb_vjs = this;
		//Calling Custom videoJs Elements Plugin
		var el_options = {
			logo : { 
					branding_logo : branding_logo,
				    product_link : product_link,
				    show_logo : true 
			},
			header : { 
					uploader : uploader,
					videotitle : videotitle,
					videoid : vid_id
			}
		}
		cb_vjs.cb_vjs_elements(el_options);

		//Calling Resolution switcher plugin
		var res_options = {
			default : default_res,
			dynamicLabel : false
		}
		cb_vjs.videoJsResolutionSwitcher(res_options);
		var  stateCheck = setInterval(function(){
		  	if (document.readyState === 'complete') {
		    	clearInterval(stateCheck);
		  		var cbVjsMenuBtn = document.querySelector('.vjs-resolution-button');
		  		if (cbVjsMenuBtn){
		  			var cbVjsMenu = cbVjsMenuBtn.children[0];
					var cbVjsMenuContent = cbVjsMenu.children[0];
					var cbVjsMenuContentRes = cbVjsMenuContent.children;
					
					for (var i = 0; i < cbVjsMenuContentRes.length; i++ ){
						cbVjsMenuContent.insertBefore(cbVjsMenuContentRes[i],cbVjsMenuContent.firstChild);
					}
		  		}
		  	}
		},100);  

		//Calling Ima Ads plugin
		if (play_ad){
			var ad_options = {
			  	ad_id: ad_id,
			    ad_code: ad_code,
			    autoplay: autoplay
			};
			cb_vjs.cb_ultimate_ads(ad_options);
		}

		//Calling TimeComments switcher plugin
		if ( cb_timecomments_plugin == 'installed'  && typeof cb_timecomments_plugin != 'undefined'){
			
			var timecomments = '{$timecomments}';
			var comments_options = {
				comments : timecomments,
				dummy : false,
				videoid : vid_id,
				userid : user_id,
				userprofile : user_profile,
				username : username,
				allowComments : allow_comments, 
				forceShow : true
			}
			cb_vjs.timecomments(comments_options);
			if (typeof timecomments != 'undefined' && timecomments != ''){
				console.log("Initialized Time Comments");
			}else{
				console.log("Time Comments are empty.. /");
			}
			
		}


		//Calling instance manager plugin for backend
		if ( video_editor_enabled && typeof video_editor_enabled != 'undefined'){
			instance_manager_settings = {
				slot_id : slot_id
			}
			cb_vjs.instanceManager(instance_manager_settings);
		}

		//Calling interactive ads plugin
		if (i_instances){
			i_instances = JSON.parse(i_instances);
			i_instances_settings = {
				enable : true,
				dummy : false,
				instances : i_instances,
			}
			cb_vjs.interactiveAds(i_instances_settings);	
		}

		new_player_height(vid_id);
	}
	//Initializing
	var cb_player = videojs('cb_video_js_'+vid_id, cb_player_setup , cb_vjs_callback);

	$(document).ready(function() {
		$(".video-js").on("contextmenu",function() {
	       return false;
	    }); 	
	});
	
	$(window).resize(function(event) {
		new_player_height(vid_id);
	});

</script>


<style type="text/css">
	.video-js {
		width: 100%;
	}
	.video-js .vjs-tech {
		height: 100% !important;
	}
	.editorpick .cb_video_js-dimensions{
		width: 100% !important;
		height: 100% !important;
	}
</style>

